const path = require( 'path' );
const HTMLPlugin = require( 'html-webpack-plugin' );
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );

const ROOT_PATH = path.resolve( __dirname );
const APP_PATH = path.resolve( ROOT_PATH, '../src' );
const BUILD_PATH = path.resolve( ROOT_PATH, '../build' );

module.exports = {
	entry: path.resolve( APP_PATH, 'index.js' ),
	output: {
		path: BUILD_PATH,
		filename: 'bundle.js'
	},
	module: {
		rules: [
			{
				test: /\.js$/,
				use: 'babel-loader'
			}, {
				test: /\.less$/,
				use: ExtractTextPlugin.extract( {
					use: [ {
						loader: 'css-loader'
					}, {
						loader: 'less-loader'
					} ],
					fallback: 'style-loader'
				} )
			}, {
				test: /\.vue$/,
				use: 'vue-loader'
			}
		]
	},
	plugins: [
		new HTMLPlugin( {
			template: path.resolve( APP_PATH, 'index.html' )
		} ),
		new ExtractTextPlugin( {
			filename: '[name].[contenthash].css'
		} )
	],
	resolve: {
		alias: {
			'vue': 'vue/dist/vue.js'
		}
	}

}